package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysDictRegion;
import com.ruoyi.system.service.ISysDictRegionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区划Controller
 * 
 * @author ruoyi
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/system/region")
public class SysDictRegionController extends BaseController
{
    @Autowired
    private ISysDictRegionService sysDictRegionService;

    /**
     * 查询区划列表
     */
    @GetMapping("/page")
    public TableDataInfo page(SysDictRegion sysDictRegion)
    {
        startPage();
        List<SysDictRegion> list = sysDictRegionService.selectSysDictRegionList(sysDictRegion);
        return getDataTable(list);
    }

    @GetMapping("/list")
    public AjaxResult list(SysDictRegion sysDictRegion)
    {
        List<SysDictRegion> list = sysDictRegionService.selectSysDictRegionList(sysDictRegion);
        return AjaxResult.success(list);
    }

    /**
     * 导出区划列表
     */
    @Log(title = "区划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDictRegion sysDictRegion)
    {
        List<SysDictRegion> list = sysDictRegionService.selectSysDictRegionList(sysDictRegion);
        ExcelUtil<SysDictRegion> util = new ExcelUtil<SysDictRegion>(SysDictRegion.class);
        util.exportExcel(response, list, "区划数据");
    }

    /**
     * 获取区划详细信息
     */
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(sysDictRegionService.selectSysDictRegionByCode(code));
    }

    /**
     * 新增区划
     */
    @Log(title = "区划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDictRegion sysDictRegion)
    {
        return toAjax(sysDictRegionService.insertSysDictRegion(sysDictRegion));
    }

    /**
     * 修改区划
     */
    @Log(title = "区划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDictRegion sysDictRegion)
    {
        return toAjax(sysDictRegionService.updateSysDictRegion(sysDictRegion));
    }

    /**
     * 删除区划
     */
    @Log(title = "区划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(sysDictRegionService.deleteSysDictRegionByCodes(codes));
    }
}
